﻿#region Usings

using Box2DX.Dynamics;
using SilverBox.Physics;

#endregion

namespace SilverBox.Helpers
{
    public static class BodyHelper
    {
        public static Body GetBodyForElement(Simulator simulator, Entity entity, BodyParameters bodyParameters)
        {
            var bodyDef = new BodyDef();
            bodyDef.Position = simulator.SimulatorContext.ScreenToWorld(entity.ElementCenter);
            bodyDef.Angle = (float) entity.ElementAngle;

            bodyParameters.SetParameters(bodyDef);

            Body body = simulator.World.CreateBody(bodyDef);
            if (body == null)
                return null;

            bodyParameters.SetParameters(body);


            ShapeHelper.CreateShapesFromElement(simulator, body, bodyParameters, entity);

            if (!bodyParameters.IsStatic)
            {
                body.SetMassFromShapes();
            }
            return body;
        }
    }
}